package com.wrx.club_management_backend.controller;

import com.wrx.club_management_backend.common.AjaxResult;
import com.wrx.club_management_backend.dto.ActivityDTO;
import com.wrx.club_management_backend.entity.ClubActivity;
import com.wrx.club_management_backend.mapper.VenueMapper;
import com.wrx.club_management_backend.service.ClubActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.json.AbstractJackson2Decoder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/activity")
public class ClubActivityController {

    @Autowired
    ClubActivityService clubActivityService;


    @GetMapping("/num")
    public AjaxResult num(){
        return clubActivityService.num();
    }

    @PostMapping("/create")
    public AjaxResult create(@RequestBody ClubActivity activity){
        return clubActivityService.create(activity);
    }

    @GetMapping("/hot")
    public AjaxResult hot(){
        return clubActivityService.hot();
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id") Long id){
        return clubActivityService.get(id);
    }

    @PostMapping("/participate/{activityId}")
    public AjaxResult participate(@PathVariable("activityId") Long activityId){
        return this.clubActivityService.participate(activityId);
    }

    // 获取活动
    @GetMapping("isParticipate/{activityId}")
    public AjaxResult isParticipate(@PathVariable("activityId") Long activityId){
        return this.clubActivityService.isParticipate(activityId);
    }

    // 获取某个活动的所有参与者
    @GetMapping("/users/{activityId}")
    public AjaxResult list(@PathVariable("activityId") Long activityId){
        return this. clubActivityService.listUserById(activityId);
    }

    // 获取待审批的活动列表
    @PostMapping("/approveList")
    public AjaxResult approveList(){
        return clubActivityService.approveList();
    }

    // 查询所有活动
    @PostMapping("/list")
    public AjaxResult list(@RequestBody ActivityDTO dto){
        return clubActivityService.getList(dto);
    }

    @Autowired
    VenueMapper venueMapper;

    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody ActivityDTO dto){
        venueMapper.updateBookingStatus(dto.getActivityId());
        return clubActivityService.approve(dto);
    }

}
